<template>
  <div>
    <Search :search="search" :reset="reset">
      <template v-slot:body> 

        <el-form-item label="单据编号" prop="docno">
          <el-input v-model="query.docno" name="docno" clearable />
        </el-form-item>
        <el-form-item label="生产工单号" prop="production_no">
          <el-input v-model="query.production_no" name="production_no" clearable />
        </el-form-item>
      </template>
    </Search>
    <div class="table-default">
      <!-- <Operate :show="open" /> -->
      <el-table :data="tableData" class="mt-3" v-loading="loading" border>
        <el-table-column prop="docno" label="单据编号" />
        <el-table-column prop="production_no" label="生产工单号" />
        <el-table-column prop="kingdee_status" label="金蝶状态" :formatter="formatter">
          <template #default="scope">
            <el-tag class="ml-2" type="warning" v-if="scope.row.kingdee_status == 0">{{ statusFormatter[scope.row.kingdee_status] }}</el-tag>
            <el-tag class="ml-2" type="success" v-if="scope.row.kingdee_status == 1">{{ statusFormatter[scope.row.kingdee_status] }}</el-tag>
            <el-tag class="ml-2" type="danger" v-if="scope.row.kingdee_status == 2">{{ statusFormatter[scope.row.kingdee_status] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="created_at" label="创建时间" />
        <el-table-column label="操作" width="100">
          <template #default="scope">
            <!-- <Update @click="open(scope.row.id)" />
            <Destroy @click="destroy(api, scope.row.id)" /> -->
            <router-link :to="{ path: '/production/pickOrderDetail', query: { id: `${scope.row.id}` } }">
              <Show />
            </router-link>
          </template>
        </el-table-column>
      </el-table>
      <Paginate />
    </div>

    <Dialog v-model="visible" :title="title" destroy-on-close>
      <Create @close="close(reset)" :primary="id" :api="api" />
    </Dialog>
  </div>
</template>

<script lang="ts" setup>
import { computed, onMounted } from 'vue'
import Create from './create.vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
import {setTableHeight} from '/admin/utils/setHeight.js'

const api = 'production/pick/order'

const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()

const tableData = computed(() => data.value?.data)

const statusFormatter = {
  0: '待推送',
  1: '推送成功',
  2: '推送失败',
}

const formatter = (row, column, value, index) => {
  return {
    0: '待推送',
    1: '推送成功',
    2: '推送失败',
  }[value]
}

onMounted(() => {
  search()
  deleted(reset)
  setTableHeight('.table-default')

})
</script>


<style lang="css">
.el-table {
  height: 80%;
}
</style>